package operation;

import book.Book;
import book.BookList;

import java.util.Arrays;

public class ShowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("显示所有图书");
        //创建新数组，不影响原数据
        int countnums = bookList.getUsedSize();
        Book[] books = new Book[countnums];
        for (int i = 0; i < countnums; i++) {
            books[i] = bookList.getBook(i);
        }
        //排序
        Arrays.sort(books,new NameCompare());
        //实例对象，这个实例对象会作为参数传递给Arrays.sort方法

        //打印
        for (int i = 0; i < countnums; i++) {
            if(books[i] != null) {
                System.out.println(books[i]);
            }
        }
    }
}
